/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package plan.mobile;

import java.util.Iterator;
import mobile.Call;
import mobile.Message;
import mobile.MobileConsumption;
import plan.Plan;
import turnover.Consumption;

/**
 *
 * @author Ale
 */
public class Simyo extends Plan {
    private double startQuote = 0d;
    private double minuteNationalCost = 0.08d;
    private double minuteInternationalCost = 0.30d;
    private double minuteSimyoCost = 0.09d;
    private double messageCost = 0.09d;

    public Simyo() {
        super.setName("Simyo");
    }

    public double getStartQuote() {
        return startQuote;
    }

    @Override
    public double getCost(Consumption consumption) {

        double total = 0d;
        MobileConsumption mc = (MobileConsumption) consumption;
        Iterator it = mc.getCallList().listIterator();
        long duration = 0;
        long durationCallMax = 600;
        while (it.hasNext()) {
            Call c = (Call) it.next();
            duration = 0;
            if (c.isSpecial()) {
                total += c.getCost();
            } else if (this.isSimyo(c) && !this.over10Minutes(c)) {
                duration += c.getDuration().changeSeconds();
            }else if(this.isSimyo(c) && this.over10Minutes(c)){
                duration += c.getDuration().changeSeconds()- durationCallMax;
                total += duration * this.minuteSimyoCost / 60;
            } else {
                duration += c.getDuration().changeSeconds();
                total += c.getDuration().changeSeconds() * this.minuteNationalCost / 60;
            }
        }
        it = mc.getMessList().listIterator();
        while (it.hasNext()) {
            Message m = (Message) it.next();
            if (m.isSpecial()) {
                total += m.getCost();
            } else {
                total += this.messageCost;
            }
        }
        total += total * 0.16d;
        return total;
    }

    public double getMessageCost() {
        return messageCost;
    }

    public double getMinuteCost() {
        return minuteNationalCost;
    }

    private boolean over10Minutes(Call c) {
        return c.getDuration().changeSeconds() > 600;
    }

    private boolean isSimyo(Call c) {
        return (c.getOperador().getName().equals("Simyo"));

    }



}
